import request from '@/utils/request';
import type { BaseBeanModel, ResponsePageData, ResponseBaseData, QueryParamModel } from '@/api/model/baseModel';
import type { downloadParam } from '@/utils/download-util';
import { downloadSysFile } from '@/utils/download-util';
const basePath = '/appsys/group/GroupRest';

/** groupusermanage1 */
export interface GroupusermanageDto extends BaseBeanModel {
  /** 群组名称 */
  groupName?: string;
  /** 群组描述 */
  groupDesc?: string;
  /** 状态 */
  validFlag?: any;
  /** 排序 */
  orderBy?: number;
  /** 状态 */
  status?: string;
  /** 用户名 */
  name?: string;
  /** 登录名 */
  loginname?: string;
  /** 密级 */
  secretlevel?: string;
  /** 后台用户 */
  type?: string;
}

/**
 * 获取主表分页数据
 * @param param 表格参数
 * @returns 表格数据
 */
export function listSysGroupByPage(param: QueryParamModel): Promise<ResponsePageData<GroupusermanageDto>> {
  return request.post(`${basePath}/searchByPage/v1`, param);
}

/**
 * 保存表单数据
 * @param form 表单数据
 */
export function saveSysGroup(form: [GroupusermanageDto]): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/saveSysGroups/v1`, form);
}

/**
 * 根据id集合删除数据
 * @param ids 选中行id集合
 */
export function delSysGroup(ids: [string]): Promise<ResponseBaseData<any>> {
  return request.delete(`${basePath}/deleteByIds/v1`, { data: ids });
}

/**
 * 导出
 * @param param 导出数据
 */
/** 导出Excel */
export function exportExcel(param: any) {
  const download = {
    url: `${basePath}/exportServerData/v1`,
    data: param,
    method: 'post'
  } as downloadParam;
  return downloadSysFile(download);
}

/**
 * 获取子表分页数据
 * @param param 表格参数
 * @param id 主表选中id
 * @returns 表格数据
 */
export function listGroupUserByPage(param: QueryParamModel, id: string): Promise<ResponsePageData<GroupusermanageDto>> {
  return request.post(`${basePath}/searchSysUserByPage/${id}/v1`, param);
}
/**
 * 添加用户数据
 * @param param 添加数据
 * @param id 主表选中id
 */
export function saveGroupUser(form: [GroupusermanageDto], id: string): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/saveUserGroup/${id}/v1`, form);
}

/**
 * 根据id集合删除数据
 * @param id 父表选中id
 * @param ids 选中行id集合
 */
export function delGroupUser(id: string, ids: [string]): Promise<ResponseBaseData<any>> {
  return request.delete(`${basePath}/deleteUserGroupByIds/${id}/v1`, { data: ids });
}
